package io.litchi.auth.Infrastructure.common.command.menupern;

import io.litchi.common.exception.LitchiException;
import jakarta.validation.Validator;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 *
 *
 * @author helang
 * @since 2025-11-25
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MenuPernSaveCommand {

    private static final Integer MENU_TYPE = 0;
    private static final Integer PERN_TYPE = 1;
    private Long id;

    @NotNull(message = "请选择上级菜单")
    private Long pid;

    @NotBlank(message = "请输入菜单标题", groups = SaveMenuGroup.class)
    private String title;

    private String route;

    @NotBlank(message = "请选择菜单图标", groups = SaveMenuGroup.class)
    private String icon;

    @NotNull(message = "请选择分类(菜单/权限)")
    private Integer type;

    @NotBlank(message = "请输入权限值", groups = SavePernGroup.class)
    private String permission;

    @NotNull(message = "请选择权限分级", groups = SavePernGroup.class)
    private Integer permissionLevel;


    public static interface SaveMenuGroup {

    }

    public static interface SavePernGroup {

    }

    //校验
    public void validate(Validator validator) {
        if (Objects.equals(this.getType(), MENU_TYPE)) {
            validator.validate(this, MenuPernSaveCommand.SaveMenuGroup.class);
        } else if (Objects.equals(this.getType(), PERN_TYPE)) {
            validator.validate(this, MenuPernSaveCommand.SavePernGroup.class);
        } else {
            throw new LitchiException("错误的菜单分类");
        }
    }

}